package bind

import (
	"encoding/json"
	"go_gui_basic_binding/frame/message"
	"go_gui_basic_binding/frame/tools"
)

var bindFunc = map[string]func(key string){}

// 事件绑定运行
func Run(param []byte) {
	mapParam := tools.JsonToMap(string(param))
	bindFunc[mapParam["name"].(string)](string(param))
}

// 执行js函数
func JsFunc(name string, param string,windowsName ...string) {
	data := map[string]interface{}{
		"name":name,
		"param":param,
	}
	mJson,_ :=json.Marshal(data)
	mString :=string(mJson)
	message.SendMessage("js_func", mString,windowsName...)
}

// 绑定方法
func Bind(funcName string,f func(key string))  {
	bindFunc[funcName] = f
}